@ECHO OFF

powershell -command "& {(get-date -format ddd)}" > today.txt
for /F %%f in (today.txt) DO SET TODAY=%%f
del today.txt

IF %TODAY%==Mon DEL "Tue Log.txt" > NUL 2>&1
IF %TODAY%==Tue DEL "Wed Log.txt" > NUL 2>&1
IF %TODAY%==Wed DEL "Thu Log.txt" > NUL 2>&1
IF %TODAY%==Thu DEL "Fri Log.txt" > NUL 2>&1
IF %TODAY%==Fri DEL "Sat Log.txt" > NUL 2>&1
IF %TODAY%==Sat DEL "Sun Log.txt" > NUL 2>&1
IF %TODAY%==Sun DEL "Mon Log.txt" > NUL 2>&1

ECHO Running Suspend.bat %DATE% %TIME% >> "%TODAY% Log.txt"

ECHO TASKKILL /F /PID EHSHELL.EXE >> "%TODAY% Log.txt"
TASKKILL /F /PID EHSHELL.EXE >> "%TODAY% Log.txt" 2>&1
ECHO.

ECHO sc stop ehRecvr >> "%TODAY% Log.txt"
sc stop ehRecvr >> "%TODAY% Log.txt" 2>&1
ECHO.

SET COUNT=0

:TRY_AGAIN
IF %COUNT%==10 GOTO BYE
SET /A COUNT=COUNT+1
ECHO Waiting for ehRecvr service to stop running...%COUNT% >> "%TODAY% Log.txt"
sc query ehrecvr|findstr "STATE.*:.*STOP_PENDING" > ServiceState.txt
for %%F in (ServiceState.txt) do if %%~zF neq 0 GOTO TRY_AGAIN
DEL ServiceState.txt > NUL 2>&1


:BYE
ECHO ------------------------------------------------ >> "%TODAY% Log.txt"
ECHO. >> "%TODAY% Log.txt"
